package sites.manager.admin.action;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Component;
import sites.manager.common.kit.Ret;
import sites.manager.common.kit.SiteInfo;
import sites.manager.common.mapper.ActionMapper;
import sites.manager.common.model.Action;

import java.util.List;

@Component
public class ActionService  extends ServiceImpl<ActionMapper, Action> {

    /**
     * 保存
     *
     * @param action
     * @return
     */
    public Ret saveAction(Action action){
        Ret ret = Ret.ok();

        action.setSiteId(SiteInfo.siteId);
        action.setStatus(SiteInfo.statusNormal);
        action.insert();

        ret.setMsg("保存成功");
        return ret;
    }

    /**
     * 获取父节点菜单
     *
     * @return
     */
    public List<Action> getParentAction(){
        LambdaQueryWrapper<Action> wrapper = new LambdaQueryWrapper<Action>();
        wrapper.eq(Action::getSiteId, SiteInfo.siteId).eq(Action::getParent, "0");
        return new Action().selectList(wrapper);
    }

    /**
     * 查询所有的资源信息
     *
     * @return
     */
    public Ret getAllAction(){
        Ret ret = Ret.ok();

        LambdaQueryWrapper<Action> wrapper = new LambdaQueryWrapper<Action>();
        wrapper.eq(Action::getSiteId, SiteInfo.siteId).eq(Action::getStatus, SiteInfo.statusNormal);
        List<Action> actionList = new Action().selectList(wrapper);

        ret.setCode("0");
        ret.setMsg("...");
        ret.setCount(0);
        ret.setData(actionList);

        return ret;
    }

}
